package com.offcn.config;


import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author: wy
 * @Date: 2022/9/23 18:44
 * <p>
 *主题模式（Topic）
 */
@Configuration
public class QueueConfig05 {

    private String topic01 = "topic01";

    private String topic02 = "topic02";

    //交换机类型 三种 type =   fanout 广播 direct 定向 topic 通配符

    private final String topicExchange = "topicExchange";


    @Bean
    public Queue queue1() {
        return new Queue(topic01);
    }

    @Bean
    public Queue queue2() {
        return new Queue(topic02);
    }

    @Bean
    public TopicExchange exchange() {
        return new TopicExchange(topicExchange);
    }


    @Bean
    public Binding bind1(Queue queue1, TopicExchange exchange) {
        return BindingBuilder.bind(queue1).to(exchange).with("topic.KeyA");
    }

    @Bean
    public Binding bind2(Queue queue2, TopicExchange exchange) {
        return BindingBuilder.bind(queue2).to(exchange).with("topic.#");
    }
}
